package com.gitee.dolt.mail.event;


import com.gitee.dolt.mail.entity.MailSendLogDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

import java.util.function.Consumer;


/**
 * 异步监听邮件发送事件
 *
 * @author LYH
 */
@Slf4j
@AllArgsConstructor
public class MailSendLogListener {

    private Consumer<MailSendLogDTO> consumer;

    @Async
    @Order
    @EventListener(MailSendLogEvent.class)
    public void handlerSysLog(MailSendLogEvent event) {
        MailSendLogDTO mailLog = (MailSendLogDTO) event.getSource();
        consumer.accept(mailLog);
    }

}
